package utils;

import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;

/**
 * Created by jimmyhsu on 2016/11/30.
 */
public class StringUtils {
    private static DecimalFormat mFormat;
    static {
        mFormat = new DecimalFormat("#.00");
    }
    public static String getUtf8String(String src) {
        if (src == null) {
            return null;
        }
        try {
            return new String(src.getBytes("ISO-8859-1"), "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return "";
    }

    public static boolean isEmpty(String src) {
        return src == null || "".equals(src) || src.equals("null");
    }

    public static boolean isAnyoneEmpty(String... src) {
        for (String s : src) {
            if (isEmpty(s)) {
                return true;
            }
        }
        return false;
    }
    public static String parseFloat(float src) {
        String scratch = mFormat.format(src);
        if (scratch.startsWith(".")) {
            return "0" + scratch;
        } else {
            return scratch;
        }
    }
}
